/*
C 语言示例：直接通过 mmap 请求大页
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>

const int HugePages_Size = 2 * 1024 * 1024;
int main()
{
    void* ptr = mmap(NULL, HugePages_Size, PROT_READ | PROT_WRITE,
        MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0);
    if (ptr == MAP_FAILED) {
        perror("mmap");
        exit(1);
    }
    munmap(ptr, HugePages_Size);

    return 0;
}
/* 测试1: 系统使能 HugePage
echo 1024 > /proc/sys/vm/nr_hugepages
sysctl -w vm.nr_hugepages=1024

确认开启: grep Huge /proc/meminfo
HugePages_Total:    1024
HugePages_Free:     1024


mmap申请成功
*/

/* 测试2: 为使能 HugePage
mmap申请失败
 */